/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.futuremind.recyclerviewfastscroll;

import ohos.agp.components.Component;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.Text;
import ohos.agp.components.element.Element;

/**
 * Utils
 *
 * @since 2021-03-23
 */
public class Utils {
    private static final int NUM = 2;
    private static DependentLayout dependentLayout;
    private static DependentLayout listContainerAbilitySlicedeidlyaout;
    private static Text textview;
    private static Text listContainerAbilitySlicetextview;

    /**
     * Utils
     */
    protected Utils() {
    }

    public static DependentLayout getListContainerAbilitySlicedeidlyaout() {
        return listContainerAbilitySlicedeidlyaout;
    }

    public static void setListContainerAbilitySlicedeidlyaout(DependentLayout listContainerAbilitySlicedeidlyaout) {
        Utils.listContainerAbilitySlicedeidlyaout = listContainerAbilitySlicedeidlyaout;
    }

    public static Text getListContainerAbilitySlicetextview() {
        return listContainerAbilitySlicetextview;
    }

    public static void setListContainerAbilitySlicetextview(Text listContainerAbilitySlicetextview) {
        Utils.listContainerAbilitySlicetextview = listContainerAbilitySlicetextview;
    }

    public static DependentLayout getDependentLayout() {
        return dependentLayout;
    }

    public static void setDependentLayout(DependentLayout dependentLayout) {
        Utils.dependentLayout = dependentLayout;
    }

    public static Text getTextview() {
        return textview;
    }

    public static void setTextview(Text textview) {
        Utils.textview = textview;
    }

    /**
     * getViewRawY
     *
     * @param view 视图
     * @return float
     */

    public static float getViewRawY(Component view) {
        int[] location = new int[NUM];
        location[0] = 0;
        location[1] = ((Component) view.getComponentParent()).getLocationOnScreen()[1];
        return location[1];
    }

    /**
     * getViewRawX
     *
     * @param view 视图
     * @return float
     */
    public static float getViewRawX(Component view) {
        int[] location = new int[NUM];
        location[0] = ((Component) view.getComponentParent()).getLocationOnScreen()[0];
        location[1] = 0;
        return location[0];
    }

    /**
     * getValueInRange
     *
     * @param min q
     * @param max q
     * @param value q
     * @return float
     */
    public static float getValueInRange(float min, float max, float value) {
        float minimum = Math.max(min, value);
        return Math.min(minimum, max);
    }

    /**
     * setBackground
     *
     * @param view q
     * @param drawable q
     */
    public static void setBackground(Component view, Element drawable) {
        view.setBackground(drawable);
    }
}
